using System;
using System.Collections.Generic;
using System.Text;

namespace HexLib
{
    public class Chronometer
    {
        private List<TimeSpan> steps = null;
        private DateTime? startTime;

        public void Start()
        {
            startTime = DateTime.Now;
        }

        public void Stop()
        {
            SetNewStep();
            startTime = null;
        }

        public void SetNewStep()
        {
            if (steps==null)
               steps = new List<TimeSpan>();

            if(startTime!=null)
                steps.Add((TimeSpan)(DateTime.Now - startTime));
        }

        public List<TimeSpan> Steps
        {
            get
            {
                return steps;
            }
        }

        public void Reset()
        {
            startTime = null;
            steps.Clear();
        }

        public bool IsStarted
        { get { return startTime != null; } }

        public TimeSpan? LastStep
        {
            get
            {
                if ((steps != null) &&
                    (steps.Count > 0))
                    return steps[steps.Count - 1];

                return null;
            }
        }
    }
}
